/**
 * Created by dqw on 2015/12/30.
 */

//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true

    },
    {
        id: 'id',
        title: '编号',
        type: 'int',
        headerClass: 'text-center width-100',
        columnClass: 'text-left width-100',
        fastSort: false,
    },
    {
        id: 'user.realName',
        title: '姓名',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'user.mobile',
        title: '手机号',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'orderNo',
        title: '订单号',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq'
    },
    {
        id: 'payNo',
        title: '第三方支付单号',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq'
    },
    {
        id: 'payType',
        title: '支付方式',
        type: 'int',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable: {
            1: $lang.payType.T1,
            2: $lang.payType.T2,
            3: $lang.payType.T3,
            4: $lang.payType.T4,
        }
    },
    {
        id: 'amount',
        title: '订单总金额(元)',
        type: 'number',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false
    },
    {
        id: 'amountLocal',
        title: '余额支付金额(元)',
        type: 'number',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false
    },
    {
        id: 'amountPay',
        title: '第三方支付金额(元)',
        type: 'number',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false
    },
    {
        id: 'sendFee',
        title: '运费(元)',
        type: 'number',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false
    },
    {
        id: 'status',
        title: '状态',
        type: 'int',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable: {
            10: $lang.orderStatus.T10,
            20: $lang.orderStatus.T20,
            30: $lang.orderStatus.T30,
            40: $lang.orderStatus.T40,
            50: $lang.orderStatus.T50,
            60: $lang.orderStatus.T60,
            61: $lang.orderStatus.T61,
        }
    },
    {
        id: 'shipCode',
        title: '快递公司编码',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'shipNo',
        title: '快递单号',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'sendAddress',
        title: '收货地址',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'sendName',
        title: '收货人姓名',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'sendPhone',
        title: '收货人手机号',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'sendMsg',
        title: '买家留言',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'sendTime',
        title: '发货时间',
        type: 'date',
        format: 'yyyy-MM-dd hh:mm:ss',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        // fastQuery: true,
        // fastQueryType: 'range',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'autoReceiveTime',
        title: '自动收货时间',
        type: 'date',
        format: 'yyyy-MM-dd hh:mm:ss',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        // fastQuery: true,
        // fastQueryType: 'range',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'payTime',
        title: '支付时间',
        type: 'date',
        format: 'yyyy-MM-dd hh:mm:ss',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        // fastQuery: true,
        // fastQueryType: 'range',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'finishTime',
        title: '完成时间',
        type: 'date',
        format: 'yyyy-MM-dd hh:mm:ss',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        // fastQuery: true,
        // fastQueryType: 'range',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'cancelTime',
        title: '关闭时间',
        type: 'date',
        format: 'yyyy-MM-dd hh:mm:ss',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        // fastQuery: true,
        // fastQueryType: 'range',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'invoiceTitle',
        title: '发票抬头',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'invoiceType',
        title: '发票类型',
        type: 'int',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        codeTable: {
            1: $lang.invoiceType.T1,
            2: $lang.invoiceType.T2
        }
    },
    {
        id: 'remark',
        title: '客服备注',
        type: 'string',
        headerClass: 'text-left width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'userRemark',
        title: '用户取消备注',
        type: 'string',
        headerClass: 'text-left width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'operation',
        title: '操作',
        type: 'string',
        headerClass: 'text-center width-300',
        columnClass: 'text-center width-300',
        fastSort: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var html='<a href="#orderGoodsList" data-toggle="modal" title="订单商品列表" data-no="' + dataNo + '"><i class="fa fa-lg fa-bars m-r-10"></i>订单商品列表</a>';
            if(html==''){
                return '暂无操作'
            }
            return html;
        }
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'order/json/list',
    exportURL: ncGlobal.adminRoot + 'order/json/export',
    exportFileName: '订单列表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    tools: 'refresh|faseQuery|export[excel]',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {bigDecimal:["amount",'totalLeft'],int:["type"],Timestamp: ["createTime"]}
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;
grid.fastQueryParameters['eq_status'] = 40;
//排序
grid.sortParameter.columnId = ['desc_createTime'];
//列表结束

//订单商品列表
var dtGridColumnsOrderGoods = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'goods.name',
        title: '商品名称',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: false,
    },
    {
        id: 'goodsDetail.goodsDetailTitle',
        title: '具体参数',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: false,
    },
    {
        id: 'goodsDetail.price',
        title: '价格',
        type: 'number',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: false,
    },
    {
        id: 'number',
        title: '购买数量',
        type: 'int',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: false,
    },
];
var dtGridOptionProductDetail = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'order/goods/list',
    exportFileName: '订单商品列表',
    columns: dtGridColumnsOrderGoods,
    gridContainer: 'dtGridContainerOrderGoods',
    toolbarContainer: 'dtGridToolBarContainerOrderGoods',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int:["orderId","number"],Timestamp:[],bigDecimal:["goodsDetail.price"]},
    onGridComplete: function (grid) {
    }
};
var grid1 = $.fn.DtGrid.init(dtGridOptionProductDetail);
grid1.fastQueryParameters = new Object();
grid1.fastQueryParameters['eq_delFlag'] = 1;

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {
        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.fastQueryParameters['eq_status'] = 40;
            grid.fastQueryParameters['lk_user.mobile_or_like_user.real_name'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    // 标的内容列表
    $("#orderGoodsList").on("show.bs.modal", function (event) {
        //获取接受事件的元素
        var  button = $(event.relatedTarget),
            //获取data 参数
            datano = button.data('no'),
            modal = $(this),
            //获取列表框中的原始数据
            gridData = grid.sortOriginalDatas[datano];
        $(".alert-danger").remove();
        grid1.fastQueryParameters = new Object();
        grid1.fastQueryParameters['eq_delFlag'] = 1;
        grid1.fastQueryParameters['eq_orderId'] = gridData.id;
        //排序
        grid1.sortParameter.columnId = 'id';
        grid1.sortParameter.sortType = 0;
        grid1.load();
    });

    //外部可调用
    return {
        bindEvent: _bindEvent,
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});